package com.qiangesoft.blog.controller.web;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qiangesoft.blog.system.entity.SysNotice;
import com.qiangesoft.blog.system.service.ISysNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 系统公告 前端控制器
 * </p>
 *
 * @author qiange
 * @since 2023-06-28
 */
@RestController
@RequestMapping("/api/notice")
@Api(tags = "系统公告")
public class ApiSysNoticeController {

    @Autowired
    private ISysNoticeService sysNoticeService;

    @GetMapping
    @ApiOperation("通知列表")
    public List<SysNotice> listByParam(@RequestParam(defaultValue = "3") Integer limit) {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(SysNotice::getIsPublish)
                .orderByDesc(SysNotice::getIsStick)
                .orderByDesc(SysNotice::getId)
                .last("limit " + limit);
        return sysNoticeService.list(queryWrapper);
    }

}

